﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public class  DangKiHocPhan : BaseData
    {
        public string MaSV { get; set; }
        public List<QLDiemHocPhan> HocPhanThamGia_Diem;
        public string HocKi { get; set; }
        public string NamHoc { get; set; }
        public string MaHP { get; set; }
        public string TenHP
        {
            get
            {
                HocPhan vid=QuanLiDSHocPhan.Instance.Find(c => (c as HocPhan).MaHocPhan == MaHP) as HocPhan;
                if (vid != null)

                    return vid.TenHocPhan;
                else return "";
            }
        }
        public DangKiHocPhan()
        {
            HocPhanThamGia_Diem = new List<QLDiemHocPhan>();
        }
        public void AddHocPhan(HocPhan hp, float diem = 0)
        {
            QLDiemHocPhan fd = HocPhanThamGia_Diem.Find(x => x.HocPhanTheoHoc.MaHocPhan == hp.MaHocPhan);
            if (fd == null)
            {
                HocPhanThamGia_Diem.Add(new
                    QLDiemHocPhan
                    {
                        HocPhanTheoHoc = hp,
                        Diem = diem
                    });
            }
        }
        public void RemoveHocPhan(string mahocphan)
        {
            QLDiemHocPhan hp =  HocPhanThamGia_Diem.Find(x=>x.HocPhanTheoHoc.MaHocPhan==mahocphan);
            if (hp != null)
            {
                HocPhanThamGia_Diem.Remove(hp);
            }
        }
        public override string ToString()
        {
            StringBuilder tr = new StringBuilder();
            bool kt = false;
            
            foreach (var item in HocPhanThamGia_Diem)
            {
               
              
           
              
                    tr.AppendLine(String.Format("{0}\t{1}\t{2}\t{3}\t{4}", MaSV, NamHoc, HocKi, item.HocPhanTheoHoc.MaHocPhan, item.Diem));
                
            }
            return tr.ToString();
        }

    }
}
